{% extends "base_sub.html" %}

{% block title %}post {{ act }}{% endblock title %}

{% block content %}
    <div id="copymove" class="new_win">
        <h1 id="win_title">post {{ act }}</h1>
        <form name="fboardmoveall" method="post" action="{{ url_for('move_update') }}" onsubmit="return fboardmoveall_submit(this);">
            <input type="hidden" name="sw" value="{{ sw }}">
            <input type="hidden" name="act" value="{{ act }}">
            <input type="hidden" name="bo_table" value="{{ current_board.bo_table }}">
            <input type="hidden" name="wr_id_list" value="{{ wr_ids }}">
            <input type="hidden" name="url" value="{{ request.headers.get("referer", "") }}">
            <input type="hidden" name="token" value="">

            <div class="tbl_head01 tbl_wrap">
                <table>
                    <caption>请选择一个或多个公告板进行复制.</caption>
                    <thead>
                    <tr>
                        <th scope="col">
                            <label for="chkall" class="blind">完整的当前页面公告板</label>
                            <input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);">
                        </th>
                        <th scope="col">公告板</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for board in boards %}
                        {% set bo_table = board.bo_table %}
                        <tr class="{% if bo_table == current_board.bo_table %}copymove_currentbg{% endif %}">
                            <td class="td_chk">
                                <label for="chk{{ loop.index }}" class="blind">{{ bo_table }}</label>
                                <input type="checkbox" value="{{ bo_table }}" id="chk{{ loop.index }}" name="chk_bo_table[]">
                            </td>
                            <td>
                                <label for="chk{{ loop.index }}">
                                    {{ board.group.gr_subject }} &gt; {{ board.bo_subject }} ({{ bo_table }})
                                    {% if bo_table == current_board.bo_table %}
                                        <span class="copymove_current">电流<span class="blind">公告板</span></span>
                                    {% endif %}
                                </label>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>

            <div class="win_btn">
                <input type="submit" value="{{ act }}" id="btn_submit" class="btn_submit">
                <button type="button" class="btn_cancel btn_close">窗口关闭</button>
            </div>
        </form>
    </div>

    <script>
        $(function() {
            $(".win_btn button").click(function() {
                window.close();
            });
        });
        
        function all_checked(sw) {
            var f = document.fboardmoveall;
            for (var i=0; i < f.length; i++) {
                if (f.elements[i].name == "chk_bo_table[]")
                    f.elements[i].checked = sw;
            }
        }
        
        function fboardmoveall_submit(f)
        {
            var check = false;
            if (typeof(f.elements['chk_bo_table[]']) != 'undefined') {
                if (typeof(f.elements['chk_bo_table[]'].length) == 'undefined') {
                    if (f.elements['chk_bo_table[]'].checked)
                        check = true;
                } else {
                    for (i=0; i < f.elements['chk_bo_table[]'].length; i++) {
                        if (f.elements['chk_bo_table[]'][i].checked) {
                            check = true;
                            break;
                        }
                    }
                }
            }
        
            if (!check) {
                alert('post ' + f.act.value + '请选择一个或多个公告板做.');
                return false;
            }

            f.token.value = generate_token();
        
            document.getElementById('btn_submit').disabled = true;
        
            f.action = "{{ url_for('move_update') }}";
            return true;
        }
    </script>
{% endblock content %}